#ifndef _ML_NBASTAT_DATALOADER_H_
#define _ML_NBASTAT_DATALOADER_H_
#include "MLCommon.h"
#include "MLDataSet.h"
#include "MLDataVector.h"
#include "MLDataPoint.h"

using namespace mylablib;

class CMLNBAStatDataLoader
{
public:
	// Constructor and Destructor
	CMLNBAStatDataLoader(void);
	~CMLNBAStatDataLoader(void);

public:
	// Types
	static const int STR_MAX_LEN = 16;
	struct PlayerSeasonData
	{
		wchar_t ilkid[STR_MAX_LEN];
		double  year;
		wchar_t firstname[STR_MAX_LEN];
		wchar_t lastname[STR_MAX_LEN];
		wchar_t team[STR_MAX_LEN];
		wchar_t leag[STR_MAX_LEN];
		double  gp;
		double  minutes;
		double  pts;
		double  oreb;
		double  dreb;
		double  reb;
		double  asts;
		double  stl;
		double  blk;
		double  turnover;
		double  pf;
		double  fga;
		double  fgm;
		double  fta;
		double  ftm;
		double  tpa;
		double  tpm;
	};

public:
	// Methods
	int Initialize(void);
	int SetYearRange(int nStartYear, int nEndYear);
	int LoadPlayerRegularSeason(const std::wstring& wstrFilename, std::vector<PlayerSeasonData>& playerSet);

private:
	// Tools
	int LoadPlayerSeasonData(const wchar_t* srcline, PlayerSeasonData& player);
	
	inline void ReadStr(wchar_t* str, const wchar_t*& p)
	{
		const wchar_t* next = wcschr(p, L'|');
		if (next == NULL)
		{
			next = p;
			while(*next) next++;
		}
		wcsncpy_s(str, STR_MAX_LEN, p, (size_t)(next - p));
		str[(size_t)(next - p)]=0;
		p = next+1;
	}

	inline void ReadDouble(double& val, const wchar_t*& p)
	{
		wchar_t str[STR_MAX_LEN];
		const wchar_t* next = wcschr(p, L'|');
		if (next == NULL)
		{
			next = p;
			while(*next) next++;
		}

		wcsncpy_s(str, STR_MAX_LEN, p, (size_t)(next - p));
		str[(size_t)(next - p)]=0;
		p = next+1;
		val = _wtof(str);
	}

private:
	// Fields
	int m_nStartYear;
	int m_nEndYear;
	const static wchar_t* _PLAYER_REASON_SCHEMA[];
};


#endif
